#include "csearchlineedit.h"
#include <QPushButton>
#include <QHBoxLayout>
#include "csearchbutton.h"
#include <string>
using namespace std;

CSearchLineEdit::CSearchLineEdit(QWidget *parent)
            :QLineEdit(parent)
{

    this->setFixedHeight(40);
    string qss = R"(QPushButton{
            background-color:#148AFF;
            background-image:url(:/resources/search.png);
            background-repeat:no-repeart;
            background-position:center;
            border-radius:20px;
    }
    )";

    this->setStyleSheet(QString::fromStdString(qss));
    setPlaceholderText("请输入搜索内容");
    this->setFixedWidth(60);
    this->setText("");


    pBtn = new CSearchButton(this);
    this->setFixedHeight(40);
    this->setMinimumWidth(400);
    this->setAttribute(Qt::WA_StyledBackground);

    QHBoxLayout *pHlay = new QHBoxLayout(this);
    pHlay->addStretch();
    pHlay->addWidget(pBtn);
    pHlay->setContentsMargins(0,0,0,0);

    this->setTextMargins(10,0, pBtn->width()+ 5, 0);

    connect(pBtn, &CSearchButton::clicked, [=]{
        emit sig_Search(this->text());
    });
}
